<template>
    <el-dialog
      class="eldialog"
      :visible.sync="visible"
      :title="title"
      :close-on-click-modal="false"
      append-to-body
      top="10vh"
      :close-on-press-escape="false"
      :before-close="removeSelecteId"
    >
      <el-form ref="roleForm" :model="dataForm" label-width="80px" :rules="rules">
        <el-form-item label="角色名称" prop="roleName">
          <el-input v-model="dataForm.roleName" placeholder="请输入角色名称" />
        </el-form-item>
        <el-form-item label="角色值" prop="description">
          <el-input v-model="dataForm.roleId" placeholder="请输入角色值" />
        </el-form-item>
      </el-form>
      <template slot="footer">
        <el-button type="success" size="medium" @click="onSubmit">保存</el-button>
        <el-button type="danger" size="medium" @click="visible = false">取消</el-button>
      </template>
    </el-dialog>
  </template>
  
  <script>
import { getRoleSave} from '@/api/datacentersg/achives/documentApi'
import store from "@/store";
  
  export default {
    name: 'ModuleAdd',
    data() {
      return {
        title: '新增角色',
        visible: false,
        valid: '',
        dataForm: {
          roleId: '',
          roleName: '',
  
        },
        // 校验规则
        rules: {
          roleName: [
            { required: true, message: '请输入角色名称', trigger: 'blur' }
          ],

          roleId: [
            { required: true, message: '请输入角色值', trigger: 'blur' }
          ],

        }
      }
    },
    mounted() {

    },
    methods: {
      async initAdd() {
        this.visible = true
      },
      removeSelecteId(){
         this.visible = false;
         this.dataForm.roleId = "";
         this.dataForm.roleName = "";
      },
      // 表单提交
      async onSubmit() {
        let params = {
         userId:store.getters.user_id.toString(),
         token: store.getters.token.toString(),
         data:{
            roleId:this.dataForm.roleId,
            roleName:this.dataForm.roleName,
            isDeleted:"1",
         }
        }

        getRoleSave(params).then((result)=>{
            if(result.result){
               this.$emit("initData");
               this.removeSelecteId();
               this.$message({
                message: '操作成功',
                type: 'success'
              });
               this.visible = false;
            }
        })



      }


    }
  }
  </script>
  
  <style scoped>
  
  </style>
  